<!DOCTYPE html>
<html lang="en">
    <head>
        {include file="public/meta" /}
        {include file="public/link" /}
    </head>
    <body data-type="index" class="theme-white">
        <div class="am-g tpl-g">
            {include file="public/header" /}
            {include file="public/left" /}
            {include file="public/content_top" /}
            <ol class="am-breadcrumb">
                <li><a href="../home/index.html" class="am-icon-home">首页</a></li>
                <li><a href="../agents/index.html">代理管理</a></li>
            </ol>
            <div class="widget am-cf">
                <div class="am-form-inline" role="form">
                    <div class="am-form-group ">
                        <input type="text" id="phone" name="phone" class="am-form-field am-input-sm" placeholder="请输入手机号" />
                    </div>
                    <div class="am-form-group ">
                        <input type="text" id="number" name="number" class="am-form-field am-input-sm" placeholder="请输入代理编号" />
                    </div>
                    <button type="button" class="am-btn am-btn-primary am-btn-sm" onclick="info_query()">查询</button>
                    <button type="button" class="am-btn am-btn-warning am-btn-sm" onclick="clear_query()">清除查询</button>

                    <a href="add_agent.html" class="am-btn am-btn-primary am-btn-sm">代理添加</a>
                    <!--<a href="add_staff.html" class="am-btn am-btn-primary am-btn-sm">员工添加</a>-->
                </div>
                <hr data-am-widget="divider" class="am-divider am-divider-default"/>

                <div class="widget-body widget-body-lg am-fr">
                    <table class="{$table}">
                        <thead>
                            <tr>
                                <th>选择</th>
                                <th>ID</th>
                                <th>代理编号</th>
                                <th>名称</th>
                                <th>代理域名</th>
                                <!--<th>代理来源</th>-->
                                <th>联系人姓名</th>
                                <th>联系人电话</th>
                                <th>手续费提成</th>
                                <th>递延费提成</th>
                                <th>盈利分配提成</th>
                                <th>代理值</th>
                                <th>状态</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody id="list">
                            {volist name="list" id="vo" empty="$empty"}
                            <tr>
                                <td><input id="rptList_chkId_3" type="checkbox" name="rptList$ctl04$chkId"></td>
                                <td>{$vo.id}</td>
                                <td>{$vo.number}</td>
                                <td>{$vo.name}</td>
                                <td>{$vo.agent_url}</td>
                                <!--<td>{$vo.agent}</td>-->
                                <td>{$vo.real_name}</td>
                                <td>{$vo.phone}</td>
                                <td>{$vo.fee_ratio}</td>
                                <td>{$vo.defer_ratio}</td>
                                <td>{$vo.wit_ratio}</td>
                                <td>
                                    {switch name="vo.grade"}
                                        {case value='1'}一级代理{/case}
                                        {case value='2'}二级代理{/case}
                                        {case value='3'}三级代理{/case}
                                    {/switch}
                                </td>
                                <td>{$vo.status}</td>
                                <td>{$vo.remake}</td>
                                <td>
                                    <a href="javascript:" onClick="del(this, {$vo.id})" class="am-btn am-btn-warning am-btn-xs">删除</a>
                                    {if condition ="$vo.status eq '禁用'"}
                                    <a href="javascript:" onClick="pass(this, {$vo.id})"  class="am-btn am-btn-success am-btn-xs">开启</a>
                                    {else/}
                                    <a href="javascript:" onClick="push(this, {$vo.id})" class="am-btn am-btn-warning am-btn-xs">禁用</a>
                                    {/if}
                                    {if condition ="$vo.grade eq 3"}
                                    <!--<a href="#" class="am-btn am-btn-warning am-btn-xs">第三等级</a>-->
                                    {else/}
                                    <a href="add_agent.html?id={$vo.id}" class="am-btn am-btn-success am-btn-xs">添加下级</a>
                                    {/if}
                                    <!--<a href="staff.html?id={$vo.id}" class="am-btn am-btn-success am-btn-xs">员工</a>-->
                                    <a href="add_agent.html?id={$vo.id}&modify=1" class="am-btn am-btn-success am-btn-xs">修改</a>
                                    <a href="login.html?id={$vo.id}" class="am-btn am-btn-success am-btn-xs" target="_blank">登录代理后台</a>
                                </td>
                            </tr>
                            {/volist}
                        </tbody>
                    </table>
                    <div class="am-pagination-left">{$page}</div>
                </div>
            </div>
        </div>
    </div>
    {include file="public/foot" /}
    <script type="text/javascript">
        function del(obj, id) {
        layer.confirm('确认要删除代理吗？', function (index) {
        $.ajax({
        type: 'POST',
                url: "{:url('index/Agents/del')}",
                data: {id: id},
                dataType: 'json',
                success: function (data) {
                layer.msg('删除成功!', {icon: 1, time: 1000});
                $(obj).parents("tr").remove();
                },
                error: function (data) {
                layer.msg('删除失败!', {icon: 0, time: 1000});
                },
        });
        });
        }

        function pass(obj, id) {
        layer.confirm('确认要开启代理吗？', function (index) {
        $.ajax({
        type: 'POST',
                url: "{:url('index/Agents/modify_recharge')}",
                data: {id: id, edit_type: 1},
                dataType: 'json',
                success: function (data) {
                layer.msg('开启成功!', {icon: 1, time: 1000});
                window.location.href = "{:url('index/Agents/index')}";
                },
                error: function (data) {
                layer.msg('开启失败!', {icon: 0, time: 1000});
                },
        });
        });
        }

        function push(obj, id) {
        layer.confirm('确认要禁用代理吗？', function (index) {
        $.ajax({
        type: 'POST',
                url: "{:url('index/Agents/modify_recharge')}",
                data: {id: id, edit_type: 0},
                dataType: 'json',
                success: function (data) {
                layer.msg('锁定成功!', {icon: 1, time: 1000});
                window.location.href = "{:url('index/Agents/index')}";
                },
                error: function (data) {
                layer.msg('锁定失败!', {icon: 0, time: 1000});
                },
        });
        });
        }

    $(function () {
        var nav = $('.left-sidebar li.sidebar-nav-link');
        nav.removeClass("active");
        nav.eq({$a}).find('ul').show();
        nav.eq({$a}).find('ul li').eq({$b}).find('a').addClass('active');
    });
        function info_query() {
        info();
        $("#form").submit();
        }
        function info() {
        $("input[name='start_query']").val($("input[name='start']").val());
        $("input[name='end_query']").val($("input[name='end']").val());
        $("input[name='phone']").val($("#phone").val());
        $("input[name='number']").val($("#number").val());
        $("input[name='status']").val($("select[name='status']").val());
        }
        function clear_query() {
        $("input[name='start_query']").val();
        $("input[name='end_query']").val();
        $("select[name='status']").val( - 1);
        $("input[name='phone']").val();
        $("input[name='number']").val();
        $("#form").submit();
        }
    </script>
</body>
</html>